package com.skyger.cmd;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;


public class JavaRunCommand extends Thread {
	String text;
	Process p;
	BufferedReader stdInput;
	BufferedReader stdError;
	BufferedWriter stdin;
	public void run(){
		String s = null;
		try {
			//p = Runtime.getRuntime().exec("java -jar E:/hello.jar");
			p = Runtime.getRuntime().exec("G:\\app\\gsky\\product\\11.2.0\\dbhome_1\\BIN\\sqlplus.exe");
        	stdInput = new BufferedReader(new  InputStreamReader(p.getInputStream(),"GBK"));
        	stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        	stdin = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
        	System.out.println("Here is the standard output of the command:\n");
        	
           /* while ((s = stdInput.readLine()) != null) {
                System.out.println(s);
            }*/
        	int c=0;
        	while ((c= stdInput.read()) != -1) {
                System.out.print((char)c);
            }
            // read any errors from the attempted command
            System.out.println("Here is the standard error of the command (if any):\n");
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }
            
            System.exit(0);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

    public static void main(String args[]) throws IOException {
    	JavaRunCommand cmd=new JavaRunCommand();
    	cmd.start();
    	while (true) {
    		String name = (new BufferedReader(new InputStreamReader(System.in))).readLine();
    		cmd.stdin.write(name);
    		cmd.stdin.write("\n");
    		cmd.stdin.flush();
		}
    }
}

